beginterrainscript;

variables;
short last,whichabil,px,py,counter;

body;

beginstate INIT_STATE;
	set_script_mode(2);
	px = get_ran(1,-1,1);
	py = get_ran(1,-1,1);
	counter = 0;
	last = get_current_tick();
break;

beginstate START_STATE;
	if(get_flag(2,20) <= 0)
		end();

	if((tick_difference(last,get_current_tick()) != 0) && (dist_to_party() <= 8)){
		whichabil = get_ran(1,0,4);

		if(whichabil == 0){
			put_sparkles_on_space(24,23,11,4);
			run_animation_sound(162);
			print_str_color("The Altar fizzles but does nothing.",2);
			}

		if(whichabil == 1){ //three skelletons
			put_jagged_zap(24,23,21,19,5);
			put_jagged_zap(24,23,28,19,5);
			put_jagged_zap(24,23,25,25,5);
			put_sparkles_on_space(21,19,3,4);
			put_sparkles_on_space(28,19,3,4);
			put_sparkles_on_space(25,25,3,4);
			run_animation_sound(53);

			if(char_on_loc(22,20) == -1){
				put_effect_on_space(22,20,5,1,1);
				place_monster(22,20,42,0);
				}
				else{
					while((char_on_loc(22 + px,20 + py) >= 0) && ((px + py == 2) || (px + py == -2))){
						px = get_ran(1,-1,1);
						py = get_ran(1,-1,1);
						}
					place_monster(22 + px,20 + py,42,0);
					put_effect_on_space(22 + px,20 + py,5,1,1);
					}

			if(char_on_loc(27,20) == -1){
				place_monster(27,20,42,0);
				put_effect_on_space(27,20,5,1,1);
				}
				else{
					while((char_on_loc(27 + px,20 + py) >= 0) && (px + py == 0)){
						px = get_ran(1,-1,1);
						py = get_ran(1,-1,1);
						}
					place_monster(27 + px,20 + py,42,0);
					put_effect_on_space(27 + px,20 + py,5,1,1);
					}

			if(char_on_loc(24,25) == -1){
				place_monster(24,25,42,0);
				put_effect_on_space(24,25,5,1,1);
				}
				else{
					while((char_on_loc(24 + px,25 + py) >= 0) && ((py == 0) && (px == 1))){
						px = get_ran(1,-1,1);
						py = get_ran(1,-1,1);
						}
					place_monster(24 + px,25 + py,42,0);
					put_effect_on_space(24 + px,25 + py,5,1,1);
					}
			print_str_color("Three skeletons raised!",3);
			run_animation_sound(-61);
			}

		if(whichabil == 2){ // curse/weaken
			while(counter != (party_size() + 1)){
				if(char_ok(counter) == TRUE){
					put_jagged_zap(24,23,char_loc_x(counter),char_loc_y(counter),4);
					put_effect_on_char(char_loc_x(counter),char_loc_y(counter),4,2);
					}
				counter = counter + 1;
				}
			run_animation_sound(46);
			set_party_status(1,-2,1);
			set_party_status(2,-2,1);
			counter = 0;
			}

		if(whichabil == 3){ // slow
			while(counter != (party_size() + 1)){
				if(char_ok(counter) == TRUE){
					put_jagged_zap(24,23,char_loc_x(counter),char_loc_y(counter),3);
					put_effect_on_char(char_loc_x(counter),char_loc_y(counter),8,2);
					}
				counter = counter + 1;
				}
			run_animation_sound(65);
			set_party_status(3,-2,1);
			counter = 0;
			}

		if(whichabil == 4){
			put_sparkles_on_space(24,23,11,4);
			run_animation_sound(162);
			print_str_color("The Altar fizzles but does nothing.",2);
			}

		last = get_current_tick();
		}
break;